/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.daoimpl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sesame.dao.AnswerDAO;
import com.sesame.domain.Answer;

/**
 * @author shubeta
 * 
 */
public class AnswerDAOImpl extends SqlMapClientDaoSupport implements AnswerDAO {

    public void addAnswer(Answer answer) {
        getSqlMapClientTemplate().insert("addAnswer", answer);
    }

    public void deleteAnswerById(Integer id) {
        getSqlMapClientTemplate().delete("deleteAnswerById", id);
    }

    public void deleteAnswerByNickName(String nickName) {
        getSqlMapClientTemplate().delete("deleteAnswerByNickName", nickName);
    }

    public void deleteAnswerByAskId(Integer askId) {
        getSqlMapClientTemplate().delete("deleteAnswerByAskId", askId);
    }

    @SuppressWarnings("unchecked")
    public List<Answer> getAllAnswer(Integer askId) {
        return (List<Answer>) getSqlMapClientTemplate().queryForList(
                "getAllAnswer", askId);
    }

    public Answer getAnswerByNickName(String nickName) {
        return (Answer) getSqlMapClientTemplate().queryForObject(
                "getAnswerById", nickName);
    }

    public void updateAnswer(Answer answer) {
        getSqlMapClientTemplate().update("updateAnswer", answer);
    }

}